import Vue from 'vue'
import Vuex from 'vuex'
// import api from '@/utils/api'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    yiText: '',
    jiText: '',
    jiList: [],
    yiList: []
  },
  mutations: {
    yiText (state, data) {
      state.yiText = data
    },
    jiText (state, data) {
      state.jiText = data
    },
    jiList (state, data) {
      state.jiList = data
    },
    yiList (state, data) {
      state.yiList = data
    }
  },
  actions: {
    // async getSlides ({ commit }) {
    //   const slides = await api.getSlides()
    //   if (!slides) return
    //   const parsedSlides = xml2json(slides).rss.channel.item
    //   const filtedSlides = parsedSlides.filter(
    //     slide => slide.opentype['#text'] === '1'
    //   )
    //   const formatedSlides = filtedSlides.map(formatSlideList)
    //   commit('slides', formatedSlides)
    // },
    // async getNews ({ state, commit }, r = Date.now(), init) {
    //   const news = await api.getNewslist(r)
    //   if (!news) return
    //   news.newslist.forEach((news) => {
    //     news.postdate = formatTime(news.postdate)
    //     news.link = `/pages/news/detail?id=${news.newsid}&title=${news.title}`
    //   })
    //   if (init) {
    //     commit('news', news.newslist)
    //   } else {
    //     commit('news', state.news.concat(news.newslist))
    //   }
    // },
    // async getTopics ({ state, commit }, init) {
    //   let rt = Date.now()
    //   if (!init) {
    //     const lastTopic = state.topics[state.topics.length - 1]
    //     rt = lastTopic.rt.replace(/[^0-9]/ig, '')
    //   }
    //   const topics = await api.getTopics(rt)
    //   if (!topics) return
    //   topics.forEach(topic => {
    //     const { id, c, t, un, vc } = topic
    //     topic.link = `/pages/quanzi/detail?id=${id}&title=${c} ${t}&author=${un}&vc=${vc}`
    //   })
    //   if (init) {
    //     commit('topics', topics)
    //   } else {
    //     commit('topics', state.topics.concat(topics))
    //   }
    // }
  }
})

export default store
